home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Demo's / Tools&Utilities / Programming / Tools Plus 2.5 / Tools Plus 2.5 (C⁄C++ & Pascal) / User Manual / 07-Picture Buttons (2 of 3) < prev    next >
Encoding:
Text File  |  1994-05-24  |  26.0 KB  |  423 lines  |  [TEXT/ttxt]

  1. Behavior and Appearance Specification
  2. `````````````````````````````````````
  3.   ProcID specifies the picture button’s appearance and behavior characteristics.  It is used by the button to determine its behavioral characteristics, and how it looks when selected or deselected, enabled or disabled, and when the button’s value is changed.  The value for this 4-byte long integer can be specified either by adding a set of constants to obtain the desired result, or using a specially defined variant record, as illustrated below:
  4.  
  5. picbutInstantEvent         Report a picture button event as soon as the
  6.                            mouse-down occurs in the button.  This option
  7.                            is best utilized with “click sensitive”
  8.                            icons, such as the ones seen in the Chooser.
  9.                            Instant events are automatically turned on
  10.                            when you turn on the “repeating events”
  11.                            option.
  12.  
  13. picbutTrackWithHilite      Draw a tracking highlight (a bold outline
  14.                            around the button, similar to the one used by
  15.                            the toolbox’s radio buttons) when the mouse
  16.                            button is down and its cursor is inside the
  17.                            button’s area.
  18.  
  19. picbutLockSelected         When the user selects the button, lock it in
  20.                            the selected state thereby disallowing the
  21.                            user to deselect it.  This option is usually
  22.                            used to produce the functionality of radio
  23.                            buttons, where a button can be turned on by
  24.                            clicking on it, but the user has to click
  25.                            another button to turn this one off.  If you
  26.                            turn on this option, the “switch selected”
  27.                            and “repeating events” options are
  28.                            automatically turned off.
  29.  
  30. picbutSwitchSelected       When the user clicks the button, reverse the
  31.                            “selection” state (i.e., if currently
  32.                            selected, switch to deselected.  If currently
  33.                            deselected, switch to selected).  This option
  34.                            produces a simple click-on/click-off type of
  35.                            button using a single stage.  If you turn on
  36.                            this option, the “lock selected” and
  37.                            “repeating events” options are automatically
  38.                            turned off.
  39.  
  40. picbutRepeatEvents         Repeated doPictButton events are produced as
  41.                            long as the mouse button is down and its
  42.                            cursor is inside the button’s area.  These
  43.                            events can optionally increment/decrement the
  44.                            button’s value at a specified rate.  This
  45.                            option is useful for button’s that control
  46.                            movement of objects, or situations where the
  47.                            button’s value may change by more than one.
  48.                            If you turn on this option, the “instant
  49.                            events” option is automatically turned off.
  50.  
  51. picbutAutoValueChg         Automatically increment/decrement the
  52.                            button’s value when it is selected by the
  53.                            user.  If this option is not used, your
  54.                            application must manually change button
  55.                            values where applicable.  Automatic value
  56.                            changing is only useful if your button has a
  57.                            range of values through which is can
  58.                            progress.
  59.  
  60. picbutScaleLinear          This option controls the speed of automatic
  61.                            value changes when the “repeat events” option
  62.                            is turned on.  After an initial pause, the
  63.                            button’s value will increment/decrement at a
  64.                            fixed rate.  This option can only be used in
  65.                            conjunction with the “automatic value change”
  66.                            option.  You may specify only one of the four
  67.                            possible rates for automatic value changes:
  68.                            Linear (default), slow acceleration, medium
  69.                            acceleration, or fast acceleration.
  70.  
  71. picbutScaleSlowAccel       Same as above, but the rate accelerates
  72.                            slowly.
  73.  
  74. picbutScaleMedAccel        Same as above, but the rate accelerates at a
  75.                            moderate rate.
  76.  
  77. picbutScaleFastAccel       Same as above, but the rate accelerates
  78.                            rapidly.
  79.  
  80. picbutValueWrap            When a button’s value reaches either the high
  81.                            or low limit, start at the opposite end of
  82.                            the range.  This option can only be used in
  83.                            conjunction with the “automatic value change”
  84.                            option.  
  85.  
  86. picbutLeftRightSplit       Clicking on the left half of the button
  87.                            decrements the button’s value, while clicking
  88.                            on the right half increments it.  You cannot
  89.                            combine this option with the top/bottom
  90.                            split.
  91.  
  92. picbutTopBottomSplit       Clicking on the bottom half of the button
  93.                            decrements the button’s value, while clicking
  94.                            on the top half increments it.  If you turn
  95.                            on this option, the “left/right split” option
  96.                            is automatically turned off.
  97.  
  98. picbutMultiStage           The button has a different image for each of
  99.                            its possible values.  Note that even with
  100.                            this option turned off, you may still decide
  101.                            to use an alternate image for a selected
  102.                            button and/or a disabled button.
  103.  
  104. picbutBigSICN3D            If you are using an SICN icon to produce a 3D
  105.                            button, you can create a slightly larger
  106.                            button (24 x 22 pixels) with more pronounced
  107.                            shading.  Without this option, SICN icons
  108.                            produce a slightly smaller button (24 x 20
  109.                            pixels).
  110.  
  111. picbutUsePICTS             Use PICTs instead of icons for the button’s
  112.                            image(s).  Note that PICTs and icons use
  113.                            different resource numbering schemes.  See
  114.                            the relevant details earlier in this chapter.
  115.  
  116. picbutGray4use8            If your 8-bit PICTs look good on 4-bit gray
  117.                            scale monitors, turn this option on to allow
  118.                            them to be used in such a way.  Otherwise, a
  119.                            4-bit PICT is required when a monitor is
  120.                            set to 4-bits.  This option can only be used
  121.                            in conjunction with the “use PICTs” option.
  122.  
  123. Selection Effects (Choose only one)…
  124.  
  125. picbutSelectDarken         Darken the button’s image when it is
  126.                            selected.
  127.  
  128. picbutSelectDarkenSICN3D   Darken and “push in” a 3D button when it is
  129.                            selected.  An SICN resource is used for the
  130.                            button’s image.  Tools Plus converts the SICN
  131.                            to a 3D color button, and formulates all the
  132.                            necessary selected and disabled images.
  133.  
  134. picbutSelectLightenSICN3D  Lighten and “push in” a 3D button when it is
  135.                            selected.  An SICN resource is used for the
  136.                            button’s image.  Tools Plus converts the SICN
  137.                            to a 3D color button, and formulates all the
  138.                            necessary selected and disabled images.
  139.  
  140. picbutSelectPushedSICN3D   “Push in” a 3D button when it is selected,
  141.                            but don’t darken or lighten the button.  An
  142.                            SICN resource is used for the button’s image.
  143.                            Tools Plus converts the SICN to a 3D color
  144.                            button, and formulates all the necessary
  145.                            selected and disabled images.  This option is
  146.                            suitable for momentary push buttons (like the
  147.                            Macintosh’s standard push button), because
  148.                            they provide little visual feedback that the
  149.                            button is selected.
  150.  
  151. picbutSelectAltImage       Use an alternate image when the button is
  152.                            selected.  If the button is multistage, a
  153.                            selected image will likely be required for
  154.                            each stage.
  155.  
  156. Disabling Effects (Choose only one)…
  157.  
  158. If a disabling effect is not specified, the global default is used as defined by the DefaultIconLook routine.
  159.  
  160. picbutDimUsingBlackLite    When the button is disabled, overlay the
  161.                            image with a black color using a “light gray”
  162.                            (25%) pattern.
  163.  
  164. picbutDimUsingWhiteLite    When the button is disabled, overlay the
  165.                            image with a white color using a “light gray”
  166.                            (25%) pattern.
  167.  
  168. picbutDimUsingWhite        When the button is disabled, overlay the
  169.                            image with a white color using a “medium
  170.                            gray” (50%) pattern.
  171.  
  172. picbutDimLeaveBorder       When the button is disabled, do not apply the
  173.                            disabling effect to the image’s border.  This
  174.                            option can be used in conjunction with any of
  175.                            the disabling effects listed above.
  176.  
  177. picbutDimAltImage          Use an alternate image when the button is
  178.                            disabled.  If the button is multistage, a
  179.                            selected image will likely be required for
  180.                            each stage.  You may have to create a
  181.                            disabled image for both the selected and
  182.                            deselected state if the button can be seen in
  183.                            such a way.
  184.  
  185. picbutDimNoChange          The button appears unchanged when it is
  186.                            disabled.  The user is beeped if they click
  187.                            on a disabled button.
  188.  
  189.   So, if you want to create a large SICN 3D picture button that locks into the selected state, lightens when selected, and is disabled by overlaying the image using a white color with a 50% gray pattern, you should use the combined constants picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite.  Alternatively, a C structure and a Pascal variant record are available to help you define the ProcID in a more intuitive way, as shown below:
  190.  
  191.  
  192. union TPPictButtonSpec {       /*Picture Button's appearance and      */
  193.                                /*  behavior specs in 2 formats…       */
  194.   struct{                      /* • Parsed into components:           */
  195.     unsigned short InstantEvent: 1;    /*  Report event on mouse-down */
  196.     unsigned short TrackWithHilite: 1; /*  Track using hilighting     */
  197.                                        /*    (like a radio button)    */
  198.     unsigned short LockSelected: 1;    /*  Lock if selected (mouse    */
  199.                                        /*    can't deselect)          */
  200.     unsigned short SwitchSelected: 1;  /*  Switch 'select' state if   */
  201.                                        /*    clicked.                 */
  202.     unsigned short RepeatEvents: 1;    /*  Repeat event when button is*/
  203.                                        /*    held.                    */
  204.     unsigned short AutoValueChg: 1;    /*  Automatically chg button's */
  205.                                        /*    value.                   */
  206.     unsigned short AutoValueScaling: 3;/*  Rate of change for button's*/
  207.                                        /*    value.                   */
  208.     unsigned short ValueWrap: 1;       /*  Button's range of values   */
  209.                                        /*    'wrap' around.           */
  210.     unsigned short LeftRightSplit: 1;  /*  Left side reduces value,   */
  211.                                        /*    right increase.          */
  212.     unsigned short TopBottomSplit: 1;  /*  Top increases value, bottom*/
  213.                                        /*    reduces.                 */
  214.     unsigned short MultiStage: 1;      /*  Button has multiple stages */
  215.     unsigned short BigSICN3D: 1;       /*  Make SICN 3D button larger */
  216.     unsigned short UsePICTS: 1;        /*  Use PICTs instead of icons */
  217.     unsigned short Gray4use8: 1;       /*  Use 8-bit color pict on    */
  218.                                        /*    4-bit gray scale monitor.*/
  219.                                        /*Selection Effects…           */
  220.     unsigned short SelectDarken: 1;       /*   Darken image           */
  221.     unsigned short SelectDarkenSICN3D: 1; /*   Darken (+push in) a 3D */
  222.                                           /*     SICN icon.           */
  223.     unsigned short SelectLightenSICN3D: 1;/*   Lighten (+push in) 3D  */
  224.                                           /*     SICN icon.           */
  225.     unsigned short SelectPushedSICN3D: 1; /*   Same color (+push) 3D  */
  226.                                           /*     SICN icon.           */
  227.     unsigned short bit19: 1;              /*   (reserved bit)         */
  228.     unsigned short bit20: 1;              /*   (reserved bit)         */
  229.     unsigned short SelectAltImage: 1;     /*   Use an alternate image */
  230.     unsigned short bit22: 1;              /*   (reserved bit)         */
  231.                                         /*Disabling Effects…          */
  232.     unsigned short DimUsingBlackLite: 1;/*  Overlay Black color, Lt   */
  233.                                         /*    Gray pattern.           */
  234.     unsigned short DimUsingWhiteLite: 1;/*  Overlay White color, Lt   */
  235.                                         /*    Gray pattern.           */
  236.     unsigned short DimUsingWhite: 1;    /*  Overlay White color, Gray */
  237.                                         /*    pattern.                */
  238.     unsigned short bit26: 1;            /*  (reserved bit)            */
  239.     unsigned short bit27: 1;            /*  (reserved bit)            */
  240.     unsigned short DimLeaveBorder: 1;   /*  Leave border when effect  */
  241.                                         /*    applied.                */
  242.     unsigned short DimAltImage: 1;      /*  Use an alternate image    */
  243.     unsigned short DimNoChange: 1;      /*  Button looks same when    */
  244.                                         /*    disabled.               */
  245.     unsigned short bit31: 1;            /*  (reserved bit)            */
  246.    } Bits;                              /*                            */
  247.    long Num;                            /* • Long equivalent          */
  248. };                                      /*                            */
  249. typedef union TPPictButtonSpec TPPictButtonSpec;
  250.  
  251.  
  252.  
  253.  
  254. TPPictButtonSpec = packed record {Picture Button's appearance &behavior}
  255.                                  {  specifications in 2 formats…       }
  256.   case integer of                {                                     }
  257.     0: (                             { • Parsed into components:       }
  258.       InstantEvent: boolean;         {     Report event on mouse-down  }
  259.       TrackWithHilite: boolean;      {     Track using hilighting, like}
  260.                                      {       a radio button.           }
  261.       LockSelected: boolean;         {     Lock if selected (mouse     }
  262.                                      {       can't deselect)           }
  263.       SwitchSelected: boolean;       {     Switch 'selected' state if  }
  264.                                      {       clicked                   }
  265.       RepeatEvents: boolean;         {     Repeat event when button is }
  266.                                      {       held down                 }
  267.       AutoValueChg: boolean;         {     Automatically change        }
  268.                                      {       button's value            }
  269.       AutoValueScaling: 0..3;        {     Rate of change for button's }
  270.                                      {       value.                    }
  271.       ValueWrap: boolean;            {     Button's range of values    }
  272.                                      {       'wrap' around             }
  273.       LeftRightSplit: boolean;       {     Left side reduces value,    }
  274.                                      {       right increases.          }
  275.       TopBottomSplit: boolean;       {     Top increases value, bottom }
  276.                                      {       reduces.                  }
  277.       MultiStage: boolean;           {     Button has multiple stages  }
  278.       BigSICN3D: boolean;            {     Create a larger SICN 3D     }
  279.                                      {       button                    }
  280.       UsePICTS: boolean;             {     Use PICTs instead of icons  }
  281.       Gray4use8: boolean;            {     Use 8-bit color pict on     }
  282.                                      {       4-bit gray monitor        }
  283.                                      {Selection Effects…               }
  284.       SelectDarken: boolean;         {     Darken image                }
  285.       SelectDarkenSICN3D: boolean;   {     Darken (and push in) a 3D   }
  286.                                      {       SICN icon.                }
  287.       SelectLightenSICN3D: boolean;  {     Lighten (and push in) a 3D  }
  288.                                      {       SICN icon.                }
  289.       SelectPushedSICN3D: boolean;   {     Same color (and push in) a  }
  290.                                      {       3D SICN icon.             }
  291.       bit19, bit20: boolean;         {      (reserved bits)            }
  292.       SelectAltImage: boolean;       {     Use an alternate image      }
  293.       bit22: boolean;                {      (reserved bit)             }
  294.                                      {Disabling Effects…               }
  295.       DimUsingBlackLite: boolean;    {     Overlay Black color using Lt}
  296.                                      {       Gray pattern              }
  297.       DimUsingWhiteLite: boolean;    {     Overlay White color using Lt}
  298.                                      {       Gray pattern              }
  299.       DimUsingWhite: boolean;        {     Overlay White color using   }
  300.                                      {       Gray pattern              }
  301.       bit26, bit27: boolean;         {      (reserved bits)            }
  302.       DimLeaveBorder: boolean;       {     Leave border when applying  }
  303.                                      {       effect.                   }
  304.       DimAltImage: boolean;          {     Use an alternate image      }
  305.       DimNoChange: boolean;          {     Button looks the same when  }
  306.                                      {       disabled.                 }
  307.        bit31: boolean;               {     (reserved bit)              }
  308.      );                              {                                 }
  309.      1: (                            {• Longint equivalent:            }
  310.        Num: longint;                 {     Specification longint       }
  311.      );                              {                                 }
  312.    end;
  313.  
  314.  
  315.  
  316.   As an example, lets create a picture button that repeats events, uses an alternate image when selected, and looks the same when disabled.  The following code sample illustrates how this is done:
  317.  
  318. procedure DoItNow;
  319.   var
  320.     ProcID: TPPictButtonSpec; {Define the variable used for the ProcID}
  321.   begin
  322.     ProcID.Num := 0;          {Initialize all the bits to zero values }
  323.     ProcID.RepeatEvents := true; {Button will produce repeating events}
  324.     ProcID.SelectAltImage := true;{Alternate image is used when button}
  325.                                   {  is selected.                     }
  326.     ProcID.DimNoChange:= true;    {Button looks the same when disabled}
  327.                                   {Create the picture button using the}
  328.                                   {  long integer part of the ProcID… }
  329.     NewPictButton(1, 441, 5, PlusIcon, ProcID.Num, enabled, notSelected,
  330.                         0, 0, 0); {                                   }
  331.  
  332.  
  333.   You can use whatever you like best as the ProcID, a single constant, several constants added together, a variable, or the long integer component of a structure or variant record.
  334.  
  335.  
  336.  
  337. Rate of Repeating Events
  338. ````````````````````````
  339.   Picture buttons have the ability to produce repeating events when they are held down.  Four predefined rates are available to control the speed at which a picture button’s value changes:
  340.  
  341.   • Linear:             The button’s value changes when the button is
  342.                         selected.  After a brief pause, the value
  343.                         continues to change at a slow and consistent
  344.                         rate.
  345.  
  346.  • Slow Acceleration:   The button’s value changes when the button is
  347.                         selected.  After a brief pause, the value
  348.                         continues to change at a rate that slowly
  349.                         accelerates.
  350.  
  351.  • Medium Acceleration: The button’s value changes when the button is
  352.                         selected.  After a brief pause, the value
  353.                         continues to change at a moderately accelerating
  354.                         rate.
  355.  
  356.  • Fast Acceleration:   The button’s value changes when the button is
  357.                         selected.  After a brief pause, the value
  358.                         continues to change at a rate that rapidly
  359.                         accelerates.
  360.  
  361.   There is yet another way to control a button’s speed, and that is by using the SetPictButtonSpeed procedure which lets you specify an exact rate (change in value per second).  When you use SetPictButtonSpeed, the specified rate takes effect immediately when the user presses the picture button.  Unlike the four standard Tools Plus acceleration rates, there is no pause between the time when the user selects the picture button and when the repeating events begin.
  362.  
  363. Note: If your application calls PollSystem more often than the picture
  364.       button’s rate of change, your application will receive doNothing
  365.       events (no event).  This produces no ill effects, but you should
  366.       be aware that it is possible to receive doNothing events between
  367.       doPictButton events.
  368.  
  369.   CONST                   {Pict Button Behavior and Appearance Specs:  }
  370.     picbutInstantEvent   = $80000000; { Report event on mouse-down     }
  371.     picbutTrackWithHilite= $40000000; { Track using hiliting, like a   }
  372.                                       {   radio button.                }
  373.     picbutLockSelected   = $20000000; { Lock if selected (mouse can't  }
  374.                                       {   deselect)                    }
  375.     picbutSwitchSelected = $10000000; { Switch 'selected' state if     }
  376.                                       {   clicked.                     }
  377.     picbutRepeatEvents   = $08000000; { Repeat event when button is    }
  378.                                       {   held down.                   }
  379.     picbutAutoValueChg   = $04000000; { Automatically change button's  }
  380.                                       {   value.                       }
  381.     picbutScaleLinear    = $00000000; { Rate of automatic value change…}
  382.     picbutScaleSlowAccel = $01000000; {    Linear, Slow Acceleration,  }
  383.     picbutScaleMedAccel  = $02000000; {    Medium Acceleration, and    }
  384.     picbutScaleFastAccel = $03000000; {    Fast Acceleration.          }
  385.     picbutLinear         = 0;         {    Linear (use in structure)   }
  386.     picbutSlowAccel      = 1;         {    Slow (use in structure)     }
  387.     picbutMedAccel       = 2;         {    Medium (use in structure)   }
  388.     picbutFastAccel      = 3;         {    Fast (use in structure)     }
  389.     picbutValueWrap      = $00800000; { Button's range of values 'wrap'}
  390.                                       {   around.                      }
  391.     picbutLeftRightSplit = $00400000; { Left side reduces value, right }
  392.                                       {   increases.                   }
  393.     picbutTopBottomSplit = $00200000; { Top increases value, bottom    }
  394.                                       {   reduces.                     }
  395.     picbutMultiStage     = $00100000; { Button has multiple stages     }
  396.     picbutBigSICN3D      = $00080000; { Create a larger SICN 3D button }
  397.     picbutUsePICTS       = $00040000; { Use PICTs instead of icons     }
  398.     picbutGray4use8      = $00020000; { Use 8-bit color pict on 4-bit  }
  399.                                       {   gray monitor.                }
  400.                                       {Selection Effects…              }
  401.     picbutSelectDarken        = $00010000; { Darken image              }
  402.     picbutSelectDarkenSICN3D  = $00008000; { Darken (and push in) a 3D }
  403.                                            {   SICN icon.              }
  404.     picbutSelectLightenSICN3D = $00004000; { Lighten (and push in) a 3D}
  405.                                            {   SICN icon.              }
  406.     picbutSelectPushedSICN3D  = $00002000; { Same color (and push in) a}
  407.                                            {   3D SICN icon.           }
  408.     picbutSelectAltImage      = $00000400; { Use an alternate image    }
  409.                                            {Disabling Effects…         }
  410.     picbutDimUsingBlackLite   = $00000100; { Overlay Black color using }
  411.                                            {   Lt Gray pattern.        }
  412.     picbutDimUsingWhiteLite   = $00000080; { Overlay White color using }
  413.                                            {   Lt Gray pattern.        }
  414.     picbutDimUsingWhite       = $00000040; { Overlay White color using }
  415.                                            {   Gray pattern.           }
  416.     picbutDimLeaveBorder      = $00000008; { Leave border when applying}
  417.                                            {   the effect.             }
  418.     picbutDimAltImage         = $00000004; { Use an alternate image    }
  419.     picbutDimNoChange         = $00000002; { Button looks the same when}
  420.                                            {   disabled.               }
  421.  
  422. ------------------------------------------------------------------------
  423.